<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>下级代理充值</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
		<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>

	<style type="text/css">
	.ext-ie .x-menu-item-icon {left: -24px; top: 0px;}
	.ext-strict .x-menu-item-icon {left: 3px; top: 3px;}
	.ext-ie6 .x-menu-item-icon {left: -24px; top: 0px;}
	</style>

<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../images/s.gif';
</script>
	<script type="text/javascript">
	Ext.onReady(function(){
	var $grid;
	//---定义修改form
	    var simple = new Ext.FormPanel({
	    //renderTo:'myf',
	    region: 'east',
        labelWidth: 80, // label settings here cascade unless overridden
        url:'../ajaxjsp/charge.jsp',
        frame:true,
        title: '代理充值',
        bodyStyle:'padding:5px 5px 0',
        width: 300,
        defaults: {width: 230},
        defaultType: 'textfield',
        items:[ new Ext.form.FieldSet({
            title: '代理信息，不可修改',
            width: 300,
            autoHeight: true,
            defaultType: 'textfield',
        items: [
        {
                fieldLabel: '编号',
                name: 'aid',
                width : '80%',
                allowBlank:false,
                readOnly:true,
                xtype:'hidden',
                blankText :'编号必须填写'
            },
            {
                fieldLabel: '代理公司名',
                name: 'acompany',
                width : '80%',
                readOnly:true
            },{
                fieldLabel: '管理员用户名',
                name: 'auname',
                width : '80%',
                readOnly:true

            },{
                fieldLabel: '短信余额',
                name: 'asmsnum',
                width : '80%',
                readOnly:true

            }
            ,{
                fieldLabel: '密码',
                name: 'apwd',
                vtype:'alphanum',
                width : '80%',
                xtype:'hidden'

            },{
                fieldLabel: '等级',
                name: 'arank',
                 width : '80%',
                 xtype:'hidden'

            },{
                fieldLabel: '是否启用',
                name: 'aavailable',
                xtype:'hidden',
                width : '80%'

            }
        ]}),

        new Ext.form.FieldSet({
            title: '短信充值',
            width: 300,
            autoHeight: true,
            defaultType: 'textfield',
            items:[
					{
						 //labelWidth: 160,
					    fieldLabel: '充值短信（条）',
					    name: 'addcharge',
					    width : '70%',
					    xtype:'numberfield'
					}
                   ]})
        ],

        buttons: [{
            text: '充值',
            handler : function(){simple.form.submit({
					waitMsg : '正在处理......',
					success : doSuccess,
					failure : function(form, action) {
						//form.reset();
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误','充值失败');}else{
							Ext.MessageBox.alert('错误','非法输入---------------');
							}
					}
				});
            }
        },{
            text: '重填',
            handler : function(){
          		simple.form.reset();
            }
        }]
    });
    //form end

	var AdminRecord = Ext.data.Record.create([
        {name: 'aid', type: 'string'},
        {name: 'auname', type: 'string'},
        {name: 'apwd', type: 'string'},
        {name: 'acompany', type: 'string'},
        {name: 'aregisttime', type: 'string'},
        {name: 'arank', type: 'int'},
        {name: 'aavailable', type: 'int'},
        {name: 'asmsnum', type: 'int'}
    ]);

    var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/proxtlist.jsp'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },AdminRecord),
        remoteSort: true
    });


    var columns = new Ext.grid.ColumnModel([
        //{header: '编号', dataIndex: 'aid',width:1},
        new Ext.grid.RowNumberer(),
        {header: '用户名', dataIndex: 'auname'},
        //{header: '密码', dataIndex: 'apwd'},
        {header: '公司名称', dataIndex: 'acompany'},
        {header: '注册日期', dataIndex: 'aregisttime'},
       // {header: '等级', dataIndex: 'arank'},
       // {header: '是否禁用', dataIndex: 'aavailable'},
        {header: '短信余额', dataIndex: 'asmsnum'}
    ]);

    columns.defaultSortable = true;

        var grid = new Ext.grid.GridPanel({
        title: '代理注册列表',
        region: 'center',
        loadMask: true,
        store: store,
        cm: columns,
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        })
    });

    store.load({params:{start:0,limit:15}});
    grid.on('rowclick',function (grid,rowIndex,event){
    var record = grid.getStore().getAt(rowIndex);
   	simple.getForm().loadRecord(record);
    });


	var viewport = new Ext.Viewport({
	renderTo:'mt',
	layout:'border',
	items:[
	grid,simple,
	{region:'south',contentEl:'inp',heigth:40}
	//{region:'east',html:'east',width:'30%'}
	]
	});

	function doSuccess(form, action){
		Ext.Msg.alert('充值成功',action.result.msg);
		simple.getForm().reset();
		store.reload();
		}

});
	</script>
  </head>

  <body>
   <div id="mt"></div>
   <div id="north1"></div>
   <div id="south"></div>
    <div id="wait" align="center"></div>
   <input id="inp" value="刷新页面" type="button" onclick="javascript:window.location.reload();"></input>
  </body>
</html>
